<?php
use think\Response;

function statusResponse($status, $message = '', $data = [])
{
    return ajax_return([
        'status' => $status,
        'message' => $message,
        'data' => $data
    ]);
}

function resultJson($array)
{
    if(isset($array['data'])) {
        $array['error'] = '';
        $code = 200;
    } elseif (isset($array['error'])) {
        $code = 400;
        $array['data'] = '';
    }
    return ajax_return([
        'code'  => $code,
        'data'  => $array['data'],
        'error' => $array['error']
    ]);
}


function ajax_return($ret, $extend = [])
{
    $ret = array_merge($ret, $extend);

    return Response::create($ret, 'json');
}


/**
 * 用户密码加密方法
 * @param  string $str      加密的字符串
 * @param  [type] $auth_key 加密符
 * @return string           加密后长度为32的字符串
 */
function user_md5($str, $auth_key = '')
{
    return '' === $str ? '' : md5(sha1($str) . $auth_key);
}